/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models;

import graph.DijkstraResult;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

/**
 *
 * @author borysfan
 */
public class ResultTableModel extends AbstractTableModel{

    private ArrayList<DijkstraResult> result = new ArrayList<DijkstraResult>();
    

    public ResultTableModel(){

    }

    public int getRowCount() {
        return result.size();
    }

    public int getColumnCount() {
        return DijkstraResult.fieldNum;
    }

    @Override
    public String getColumnName(int columnIndex) {
       
        switch(columnIndex){
            case 0: return "ID";
            case 1: return "Ilość miast";
            case 2: return "Dystans (km)";
            case 3: return "Prędkość (km/h)";
            case 4: return "Czas (min)";
        }
        return "";
    }

    public DijkstraResult getRow(int i){
        if(i>=0 && i<result.size()){
            return result.get(i);
        }
        return null;
    }

   

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0: return rowIndex+1;
            case 1: return result.get(rowIndex).getCityNum();
            case 2: return result.get(rowIndex).getDistance();
            case 3: return result.get(rowIndex).getAvgSpeed();
            case 4: return result.get(rowIndex).getTime()*60;
        }
        return "";
    }

   

    public void addResult(DijkstraResult dr){
        result.add(dr);
    }

    public void clear(){
        result.clear();
    }

   

}
